#! /usr/bin/env python

import os
import pygame
import sys

from pygame.locals import *

start_menu_font = os.path.join ('data/fonts', 'BAM.ttf') # Load the BAM font

'''
class YesOrNoFrame (pygame.sprite.Sprite):
    # This creates a frame that will be used to hold the yes and no buttons
    def __init__(self):
        pygame.sprite.Sprite.__init__(self)

        self.surface = pygame.Surface ((300,200))
        self.rect = pygame.Rect((489,449),(300,200))
        self.yesButton = YesOrNoButton ('YES', 90, 70)
        self.noButton  = YesOrNoButton ('NO', 180, 70)
        self.surface.fill ((255,0,0))
        self.answer = None

    def Show (self, surface, x, y, clicked):
        self.yesButton.Update (x, y, clicked)
        self.noButton.Update (x, y, clicked)
        self.yesButton.Show (self.surface)
        self.noButton.Show (self.surface)
        surface.blit (self.surface, self.rect)

        if self.yesButton.answer != None:
            self.answer = self.yesButton.answer
        if self.noButton.answer != None:
            self.answer = self.noButton.answer
        if self.answer != None:
            self.yesButton.kill ()
            self.noButton.kill ()
            return self.answer
        self.kill()

class YesOrNoButton (pygame.sprite.Sprite):
    fontcolor = [255, 255, 255] #Set font color to white
    font_size = 30

    def __init__ (self, yesOrNo, xloc, yloc):
        pygame.sprite.Sprite.__init__ (self)
        self.text      = yesOrNo
        self.x         = xloc
        self.y         = yloc
        self.answer    = None
        self.fontcolor = self.fontcolor
        self.font      = pygame.font.Font (start_menu_font,
                                      self.font_size)
        self.image     = self.font.render (yesOrNo, 1, self.fontcolor)
        self.rect      = self.image.get_rect ()
        self.rect.topleft   = [self.x, self.y]
        self.mouse_over    = False
        self.click         = False
        self.sound = pygame.mixer.Sound (os.path.join('data/audio',
            '80921__JustinBW__buttonchime02up.wav'))
        self.sound.set_volume (0.3)
        self.mouse_left = True
        self.bottomx = self.image.get_width() + self.x
        self.bottomy = self.image.get_height() + self.y

    def Update (self, mouse_x, mouse_y, clicked):
        # is mouse over the button?
        if ((mouse_x >= self.x) and (mouse_x <= self.bottomx) and
            (mouse_y >= self.y) and (mouse_y <= self.bottomy)):
            self.mouse_over = True

            if self.mouse_left==True:
                self.mouse_left = False
                self.sound.play ()

        else:
            self.mouse_over = False
            self.mouse_left = True

        if self.mouse_over:
            if self.click:
                if self.text == 'YES':
                    self.answer = 1
                else:
                    self.answer = 2
            else:
                self.mouse_over = False

    def Show (self, surface):
        surface.blit (self.image, self.rect)
'''

class StartMenuButton (pygame.sprite.Sprite):
    fontcolor = [0,0,0] #Set font color to black
    font_size = 40

    def __init__(self, name, option, x, y, arg):
        pygame.sprite.Sprite.__init__(self)
        self.value     = name
        self.option    = option
        self.arg       = arg
        self.x         = x
        self.y         = y

        self.fontcolor = StartMenuButton.fontcolor
        self.font      = pygame.font.Font (start_menu_font,
                                      StartMenuButton.font_size)
        self.image     = self.font.render (self.value, 1, self.fontcolor)
        self.rect      = self.image.get_rect ()
        self.rect.topleft   = [self.x, self.y]
        self.mouse_x, self.mouse_y = 0, 0
        self.mouse_over    = False
        self.click         = False
        self.sound = pygame.mixer.Sound (os.path.join('data/audio',
            '80921__JustinBW__buttonchime02up.wav'))
        self.sound.set_volume (0.3)
        self.mouse_left = True

        self.bottomx = self.image.get_width() + self.x
        self.bottomy = self.image.get_height() + self.y

    def Update (self, mouse_x, mouse_y, clicked):
        self.click = clicked
        self.mouse_x, self.mouse_y = mouse_x, mouse_y

        # is mouse over the button?
        if ((self.mouse_x >= self.x) and
            (self.mouse_x <= self.bottomx) and
            (self.mouse_y >= self.y)  and
            (self.mouse_y <= self.bottomy)):

            self.mouse_over = True

            if self.mouse_left==True:
                self.mouse_left = False
                self.sound.play ()

        else:
            self.mouse_over = False
            self.mouse_left = True

        if self.mouse_over:
            if self.click:
                if self.option != 0:
                    if self.arg != False:
                        self.option(self.arg)
                    else:
                        self.option()
                    self.click = False
            else:
                self.mouse_over = False

    def Show (self, surface):
        surface.blit (self.image, self.rect)

class ButtonMove (pygame.sprite.Sprite):
    fontcolor = [0,0,0] #Set font color to black
    font_size = 40

    def __init__(self, name, option, x, y, arg):
        pygame.sprite.Sprite.__init__(self)
        self.value     = name
        self.option    = option
        self.arg       = arg
        self.x         = x
        self.y         = y

        self.fontcolor = ButtonMove.fontcolor
        self.font      = pygame.font.Font (start_menu_font,
                                      ButtonMove.font_size)
        self.image     = self.font.render (self.value, 1, self.fontcolor)
        self.rect      = self.image.get_rect ()
        self.rect.topleft   = [self.x, self.y]
        self.mouse_x, self.mouse_y = 0, 0
        self.mouse_over    = False
        self.click         = False
        self.sound = pygame.mixer.Sound (os.path.join('data/audio',
            '80921__JustinBW__buttonchime02up.wav'))
        self.sound.set_volume (0.3)
        self.mouse_left = True

        self.bottomx = self.image.get_width() + self.x
        self.bottomy = self.image.get_height() + self.y

    def Update (self, mouse_x, mouse_y, clicked):
        self.click = clicked
        self.mouse_x, self.mouse_y = mouse_x, mouse_y
        self.rect.topleft = (self.mouse_x, self.mouse_y)
        print (str(self.mouse_x) + ' ' + str(self.mouse_y))

    def Show (self, surface):
        surface.blit (self.image, self.rect)
